function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function () {
			oldonload();
			func();
		};
	}
}

function insertAfter(newElement, targetElement) {
	var parent = targetElement.parentNode;
	if(parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	} else {
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
}

function clearchild(obj) {
	var object = $GET(obj);
	while(object.childNodes.length > 0) {
		object.removeChild(object.childNodes[0]);
	}
}

function tourl(url) {
	location.href = url;
}

function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();

	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}

	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
			return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; } 
}

function echoxml(root,name,i){
	if(root.getElementsByTagName(name)[i].childNodes[0]){
		name = root.getElementsByTagName(name)[i].childNodes[0].nodeValue;
	}else{
		name = '';	
	}
	return name;
}

function $CREATEA(ahref, atarget, atitle) {
	var tempa = document.createElement("a");
	if(ahref != "") {tempa.href = ahref;} else {tempa.href = "#";}
	if(atarget != "") {tempa.target = atarget;}
	if(atitle != "") {tempa.title = atitle;}
	return tempa;
}

function $CREATEIMG(imgid, imgsrc, imgwidth, imgheight) {
	var tempimg = document.createElement("img");
	if(imgid != "") {tempimg.id = imgid;}
	if(imgsrc != "") {tempimg.src = imgsrc;}
	if(imgwidth != "") {tempimg.width = imgwidth;}
	if(imgheight != "") {tempimg.height = imgheight;}
	return tempimg;
}

function subheight() {
	var mainheight = $GET("mainPanel").scrollHeight;
	$GET("leftPanel").style.height = mainheight+"px";
	$GET("rightPanel").style.height = mainheight+"px";
}

function addfavorite() {
	if (document.all)
	{ window.external.addFavorite('http://www.dlruihai.com','大连瑞海'); }
	else if (window.sidebar)
	{ window.sidebar.addPanel('大连瑞海', 'http://www.dlruihai.com', ""); }
}

function substr(str, len) {
	if(!str || !len) {
		return "";
	}
	
	if(str.length > len) {
		return str.substring(0, len)+"...";
	} else {
		return str;
	}
}

function $GET(id) {return document.getElementById(id);}

function $CREATE(type) {return document.createElement(type);}

function $CREATETEXT(text) {return document.createTextNode(text);}